package com.zxl.designpattern.structure.decorator;

/**
 * 装饰器模式测试类
 * @author zxl
 */
public class Test {
    public static void main(String[] args) {
        // 基础车型
        Car car = new BasicCar();
        System.out.println(car.getDescription() + "  价格: " + car.getCost() + "元");

        // 添加高级音响
        car = new PremiumSoundSystem(car);
        System.out.println(car.getDescription() + "  价格: " + car.getCost() + "元");

        // 再添加自动驾驶
        car = new Autopilot(car);
        System.out.println(car.getDescription() + "  价格: " + car.getCost() + "元");

        /*IO流中的包装类使用到了装饰者模式。
        FileWriter fw = new FileWriter("path");
        BufferedWriter bw = new BufferedWriter(fw);*/
    }
}    